package org.littlesun.management.address;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.List;

import lombok.Getter;
import lombok.ToString;

@ToString(exclude={})
public class MatchResult {
	@Getter private MatchResult parent;
	@Getter private Object matchedObject;
	@Getter private String matchedOrginalText;
	@Getter private String textAfterMatch;
	@Getter private List<String> suggestions;
	
	public MatchResult(MatchResult parent, Object matchedObject, String matchedOrginalText, String textAfterMatch) {
		this(parent, matchedObject, matchedOrginalText, textAfterMatch, Collections.<String>emptyList());
	}
	
	public MatchResult(MatchResult parent, Object matchedObject, String matchedOrginalText, String textAfterMatch, List<String> suggestions) {
		this.parent = parent;
		this.matchedObject = matchedObject;
		this.matchedOrginalText = matchedOrginalText;
		this.textAfterMatch = textAfterMatch;
		this.suggestions = new ArrayList<String>(suggestions);
	}

	public boolean isSuccess() {
		return this.matchedObject != null;
	}
	
	public void addSuggestions(Collection<String> suggestions) {
		this.suggestions.addAll(suggestions);
	}
	
	public String getFullMatchedOrginalText() {
		if (parent == null) {
			return this.matchedOrginalText;
		}
		else {
			return parent.getFullMatchedOrginalText() + this.matchedOrginalText;
		}
	}
}